package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.common.utils.MD5Utils;
import com.itheima.dao.MemberDao;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @version v1.0
 * @date 2019/10/14 21:45
 * @description TODO
 **/
@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {


    @Autowired
    private MemberDao memberDao;

    //根据telephone判断该用户是否为会员
    @Override
    public Member findByTelephone(String telephone) {
       return memberDao.findByTelephone(telephone);
    }

    //新增会员
    @Override
    public void add(Member member) {
        if (member.getPassword() != null) {
            member.setPassword(MD5Utils.md5(member.getPassword()));
        }
        memberDao.add(member);
    }

    //根据月份查询当前月份之前所有的用户数据
    @Override
    public List<Integer> findCountByMonth(List<String> queryDataParm) {
        List<Integer> result = new ArrayList<>();

        //封装查询月份
        for (String date : queryDataParm) {
            date = date + ".31";

           int count= memberDao.findCountByMonth(date);
            result.add(count);
        }
        return result;
    }
}